/*
 * This file is part of the Gwt-Generator project and was written by Henri Darmet for Objet Direct
 * <http://wwww.objetdirect.com>
 * 
 * Copyright © 2009 Objet Direct
 * 
 * Gwt-Generator is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * Gwt-Generator is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with Gwt-Generator. If not, see <http://www.gnu.org/licenses/>.
 */

package com.objetdirect.seam;

import junit.framework.TestCase;

import com.objetdirect.engine.TestUtil;

public class TestPageDescriptor extends TestCase {
	
	public static String[] testSimplePageJavaText = {
		"package com.objetdirect.actions;",
		"",
		"import org.jboss.seam.annotations.Name;",
		"import org.jboss.seam.annotations.Scope;",
		"import org.jboss.seam.core.Conversation;",
		"import org.jboss.seam.ScopeType;",
		"",
		"@Name(\"editAgencies\")",
		"@Scope(ScopeType.CONVERSATION)",
		"public class EditAgenciesAnimator {",
		"",
		"",
		"	public EditAgenciesAnimator() {",	
		"		if (Conversation.instance().isLongRunning()) {",
		"			Conversation.instance().end(true);",
		"			Conversation.instance().leave();",
		"		}",
		"		Conversation.instance().begin();",
		"	}",
		"",
		"",
		"}"
	};
	
	public static String[] testSimplePageFaceletText  = {
		"<!DOCTYPE composition PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"", 
		"			\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
		"<ui:composition xmlns=\"http://www.w3.org/1999/xhtml\"",
		"	xmlns:s=\"http://jboss.com/products/seam/taglib\"",
		"	xmlns:ui=\"http://java.sun.com/jsf/facelets\"",
		"	xmlns:f=\"http://java.sun.com/jsf/core\"",
		"	xmlns:h=\"http://java.sun.com/jsf/html\"",
		"	xmlns:ice=\"http://www.icesoft.com/icefaces/component\"",
		"	template=\"/layout/template.xhtml\">",
		"",
		"<ui:define name=\"body\">",
		"",
		"	<h:messages styleClass=\"message\"/>",
		"",
		"	<ice:form id=\"pageForm\">",
		"		<ice:panelGroup	styleClass=\"formBorderHighlight\">",
		"",
		"			<div class=\"dialog\">",
		"			</div>",
		"		</ice:panelGroup>",
		"	</ice:form>",
		"</ui:define>", 
		"</ui:composition>"
	};

	public void testSimplePage() {
		Seam.clear();
		PageDescriptor page = 
			new PageDescriptor("com.objetdirect.actions", "EditAgencies", "views", "edit-agencies");
		page.build();
		TestUtil.assertText(page.getJavaText(),
				testSimplePageJavaText
		);
		TestUtil.assertText(page.getFaceletText(),
				testSimplePageFaceletText
		);
	}

	public void testIdGenerator() {
		Seam.clear();
		PageDescriptor page = 
			new PageDescriptor("com.objetdirect.actions", "EditAgencies", "views", "edit-agencies");
		assertEquals("id", page.makeId("id"));
		assertEquals("id1", page.makeId("id"));
	}
	
}
